package com.ciwong.epaper.modules.viedoexplantion.util;

import android.content.Context;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.RelativeLayout;


/**
 * Created by gaolinhua on 2016/5/26.
 */
public class VideoLayoutParams {
    public static RelativeLayout.LayoutParams computeContainerSize(Context context, int mWidth, int mHeight) {
        int width =getScreenWidth(context);
        int height = width * mHeight / mWidth;
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT);
        params.width = width;
        params.height = height;
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        return params;
    }

    public static int getScreenWidth(Context context){
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        return width;
    }


    public static ViewGroup.LayoutParams changeContainerSize(Context context, ViewGroup.LayoutParams params, int mWidth, int mHeight) {
        int width =getScreenWidth(context);
        int height = width * mHeight / mWidth;
        params.width = width;
        params.height = height;
        return params;
    }

//    public static RelativeLayout.LayoutParams computeContainerSize(Context context, int mWidth, int mHeight) {
//        int width =getScreenWidth(context);
//        int height = width * mHeight / mWidth;
//        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
//                RelativeLayout.LayoutParams.MATCH_PARENT,
//                RelativeLayout.LayoutParams.MATCH_PARENT);
//        params.width = width;
//        params.height = height;
//        params.addRule(RelativeLayout.CENTER_IN_PARENT);
//        return params;
//    }
}
